package com.bmadmin.controller.cus;

import com.bmadmin.domain.DataSourcePOJO;
import com.bmadmin.domain.LayUiDataTablePOJO;
import com.bmadmin.domain.NormalResult;
import com.bmadmin.service.DataSourceService;
import com.bmadmin.util.BMUtil;
import com.bmadmin.util.DataSource;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by SEELE on 2017/12/17.
 */
@RestController
@RequestMapping("/datasource")
public class DataSourceController {
    private Logger logger = LogManager.getLogger(this.getClass().getName());

    @Autowired
    DataSourceService dataSourceService;

    /**
     * 查询数据源列表
     */
    @GetMapping("/getList")
    public LayUiDataTablePOJO getDataSourceList(DataSourcePOJO dataSourcePOJO){
       return dataSourceService.getDataSourceList(dataSourcePOJO);
    }

    /**
     * 新增数据源
     */
    @PostMapping(value = "/insert",produces = "application/json")
    public NormalResult insertDataSource(@RequestBody DataSourcePOJO dataSourcePOJO){
        NormalResult result = new NormalResult();
        if(BMUtil.isNullOrEmpty(dataSourcePOJO)){
            result.setCode("9999");
            result.setMsg("传入对象为空");
            return result;
        }

        result=dataSourceService.insertDataSource(dataSourcePOJO);
        return result;
    }
    /**
     * 修改数据源
     */
    @PostMapping(value = "/update",produces = "application/json")
    public NormalResult updateDataSource(@RequestBody DataSourcePOJO dataSourcePOJO){
        NormalResult result = new NormalResult();
        if(BMUtil.isNullOrEmpty(dataSourcePOJO)){
            result.setCode("9999");
            result.setMsg("传入对象为空");
            return result;
        }

        result = dataSourceService.updateDataSource(dataSourcePOJO);
        return result;
    }

    /**
     * 删除数据源
     * @param dataSourcePOJO
     * @return
     */
    @PostMapping("/delete")
    public NormalResult deleteDataSource(DataSourcePOJO dataSourcePOJO) {
        NormalResult result = new NormalResult();
        if(BMUtil.isNullOrEmpty(dataSourcePOJO)){
            result.setCode("9999");
            result.setMsg("传入对象为空");
            return result;
        }

        result = dataSourceService.deleteDataSource(dataSourcePOJO);
        return result;
    }


}
